<template>
  <div class="box">
    <!-- 页面顶部的bar页面 -->
    <div class="boxtop">
      <van-nav-bar title="车系选择">
        <template #left>
          <van-icon
            name="arrow-left"
            color="#fff"
            size="18"
            @click="clickLeft"
          ></van-icon>
        </template>
      </van-nav-bar>
    </div>
    <!-- 搜索栏 -->
    <div class="searchbox">
      <van-search
        v-model="value"
        placeholder="请输入搜索关键词"
        input-align="center"
      />
      <!-- 索引栏 -->
      <van-index-bar highlight-color>
        <span class="allcar">全部</span>
        <div
          v-for="(item, index) in this.carSerier"
          @click="clickCarSrier(item)"
          :key="index"
        >
          <!-- 这里不需要ABCD这些索引 -->
          <!-- <van-index-anchor >
        </van-index-anchor> -->
          <span class="seriesName">{{ item.seriesName }}</span>
        </div>
        <!-- 在文本框中应该循环数组，然后添加点击事件，或者根据自己的索引值然后处理事件 -->
      </van-index-bar>
    </div>
  </div>
</template>
<script>
import { CarSeries } from '@/api/user'
export default {
  data () {
    return {
      value: '',
      // 车系选择
      carSerier: []
    }
  },
  created () {
    this.getAllInfo()
  },
  methods: {
    async getAllInfo () {
      console.log(this.$route.query.nameId)
      try {
        console.log(this.$route.query.nameId)
        const { data } = await CarSeries({ brandId: this.$route.query.nameId })
        this.carSerier = data.data
        console.log(data.data)
      } catch (err) {
        this.$toast('获取失败')
      }
    },
    ClickText () {
      console.log('打印搜索栏')
      this.$router.push('/carname')
    },
    clickCarSrier (val) {
      console.log(val)
      // 将车系存入vuex中
      this.$store.commit('gainserier', val.seriesName)
      // 路由跳转
      this.$router.push({
        path: '/carmodel',
        query: { serierIn: val.seriesId }
      })
    },
    clickLeft () {
      this.$router.back()
    }
  }
}
</script>
<style lang="less" scoped>
.box {
  // background-color: #f6f6f9;
  .allcar {
    display: inline-block;
    margin-left: 10px;
    width: 40px;
    height: 16px;
    font-size: 13px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #a4a4a4;
    line-height: 16px;
  }
  .seriesName {
    display: inline-block;
    height: 21px;
    font-size: 14px;
    font-weight: 400;
    margin-left: 10px;
    margin-top: 30px;
    font-family: PingFangSC-Regular, PingFang SC;
  }
}
</style>
